{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LATE (*IN-FREQUENT*) RIDERS ONLY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "10668"
      ],
      "text/latex": [
       "10668"
      ],
      "text/markdown": [
       "10668"
      ],
      "text/plain": [
       "[1] 10668"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import_and_maybe_install <- function(pkgs){\n",
    "    missing_packages <- character(0)\n",
    "    for(pkg in pkgs){\n",
    "        tryCatch({\n",
    "            require(pkg, character.only=TRUE )\n",
    "        },warning=function(err){\n",
    "            missing_packages <<- c(missing_packages,pkg)\n",
    "        })\n",
    "    }\n",
    "    if(length(missing_packages)){\n",
    "            install.packages(missing_packages)\n",
    "            sapply(missing_packages, require, character.only=TRUE)\n",
    "    }\n",
    "    invisible(NULL)\n",
    "}\n",
    "import_and_maybe_install(c(\"data.table\", \"feather\", \"formula.tools\"))\n",
    "Sys.getpid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_DIR <- \"~/connector/20200226/analytic_datasets\"\n",
    "\n",
    "commute_ride_data <- read_feather( file.path(DATA_DIR,\"commute_ride_data.feather\"))\n",
    "setDT(commute_ride_data)\n",
    "\n",
    "# FACTOR VARIABLES\n",
    "stopifnot(commute_ride_data[,class(fAid) == \"factor\"]) # rider id\n",
    "stopifnot(commute_ride_data[,class(fDate) == \"factor\"]) # date id\n",
    "\n",
    "route_field <- sprintf(\"route_%s_10_ride\",1:21)\n",
    "\n",
    "commute_ride_data[,I405HOV:=0 + (date > as.Date(\"2015-09-25\"))]\n",
    "#commute_ride_data[,.N,keyby=.(date,I405HOV)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FILTER on {{ LATE }}RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Early Riders"
     ]
    },
    {
     "data": {
      "text/html": [
       "3908"
      ],
      "text/latex": [
       "3908"
      ],
      "text/markdown": [
       "3908"
      ],
      "text/plain": [
       "[1] 3908"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Data\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3354470</td><td>805199 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 3354470 & 805199 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 3354470 | 805199  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 3354470 805199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Late riders only\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1562314</td><td>164677 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 1562314 & 164677 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 1562314 | 164677  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 1562314 164677"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dates = commute_ride_data[,.N,keyby=.(date,fDate)]\n",
    "MAX_DATE = dates[15,date]\n",
    "\n",
    "early_riders = commute_ride_data[date <= MAX_DATE & did_ride,1,keyby=aid][,V1:=NULL]\n",
    "cat(\"Number of Early Riders\")\n",
    "early_riders[,.N]\n",
    "\n",
    "cat(\"Full Data\\n\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "setkey(commute_ride_data,aid)\n",
    "commute_ride_data = commute_ride_data[!early_riders]\n",
    "\n",
    "cat(\"Late riders only\\n\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "#commute_ride_data[,1,aid][,.N]\n",
    "#commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV),.N]\n",
    "#commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV),1,aid][,.N]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CALCULATE FAVORITE ROUTE\n",
    "commute_ride_data$favorite_route <- apply(\n",
    "    as.matrix(commute_ride_data[,sprintf(\"route_%s_10_ride\",1:21),with=FALSE]),\n",
    "    1,\n",
    "    function(x){\n",
    "        routes = which(x == max(x))\n",
    "        if(length(routes) == 1){\n",
    "            routes\n",
    "        }else{\n",
    "            sample(routes,1)\n",
    "        }\n",
    "    })\n",
    "\n",
    "commute_ride_data[, f_favorite_route:= as.factor(favorite_route) ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Dictionary\n",
    "\n",
    "Each record represents one rider commute opportunty (rider / date / commute).\n",
    "\n",
    "**Note that** there is one record for each commute / data for every rider \n",
    "*After their first ride date*.  This is because the choice to ride (`did_ride`) \n",
    "is conditioned on the rider's history of riding, and which is not available \n",
    "on thier first ride.\n",
    "\n",
    "#### Identifiers\n",
    "* **aid**: Rider number (anonomyzed Numeric)\n",
    "* **fAid**: Rider number (anonomyzed Factor)\n",
    "* **date**: Date of the ride (as Date)\n",
    "* **fDate**: Date of the ride (as Factor)\n",
    "* **AfternoonId**: Function of Date, only true for Route 5\n",
    "\n",
    "#### Main outcome / predictor\n",
    "* **did_ride**: Did the rider ride on this date?\n",
    "* **imputed_new_buses**: The weighted average of the fraction of new busses \n",
    "     on the routes the rider took on the last (up to) 10 trips\n",
    "\n",
    "#### Time since last ride\n",
    "* **commutes_since_last_ride**: Number of commutes since rider's last ride (numeric; range 1 - 461)\n",
    "* **f_commutes_since_last_ride**: Number of commutes since rider's last ride (factor; range \"1\" - \"40+\")\n",
    "     \n",
    "#### Date based indicators\n",
    "* **SR520WBHOV**: SR 520 West Bound is open (Function of the date)\n",
    "* **SR520EBHOV**: SR 520 East Bound is open (Function of the date)\n",
    "* **I405HOV**: Is a 405 HOV is open (Function of the date )\n",
    "* **Route5Expansion**: Route 5 expanded (Function of Date )\n",
    "\n",
    "#### Features based on the rider's history\n",
    "* **route_X_10_ride** (e.g. `route_3_10_ride`):  Fraction of the rider's last 10 rides that were taken on route X\n",
    "* **is_peak_10_ride**: Fraction of the rider's last 10 rides that were taken **during peak traffic**\n",
    "* **IsESOther_10_ride**: Fraction of the rider's last 10 rides that were taken on **EastSide (other) routes**\n",
    "* **IsRouteSeattle_10_ride**: Fraction of the rider's last 10 rides that were taken on **Seattle Routes**\n",
    "* **Is405North_10_ride**: Fraction of the rider's last 10 rides that were taken on **I 405 North Routes**\n",
    "* **IsCoach_10_ride**: Fraction of the rider's last 10 rides that were taken on  **Coach (as opposed to shuttle) busses**\n",
    "* **first_stop_10_ride**: Fraction of the rider's last 10 rides that were taken from **the last AM stop**\n",
    "* **last_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on  **the first AM stop**\n",
    "* **single_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on **a Single Stop Route**\n",
    "* **vehicle_is_new_10_ride**: Fraction of the rider's last 10 rides that were taken on **a new vehicle**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Handy Utility function for fitting models and gathering summary statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' A cute little function for fitting a model and pulling out the headline statistics\n",
    "#'\n",
    "#' @param data A dataset for fitting the model\n",
    "#' @param model A number for identifying the model in a table (these second field in the \"coef\" output)\n",
    "#' @param lhs The left hand side of the model (as a string)\n",
    "#' @param predictors The effects of interested.  Specifically these are the effects that will be pulled out in the summary table\n",
    "#' @param adjust_for The fixed effects that will be included in the right hand side but not pulled out into the summar table\n",
    "#'\n",
    "#' @return A list containing the glm model (`$model`), and a matrix of interesting statistics from the\n",
    "#'       various models (`$coef`)\n",
    "\n",
    "fit_ridership_logit_models <- function(data,\n",
    "                                        model=1,\n",
    "                                        lhs=\"did_ride\",\n",
    "                                        predictors=\"new_fraction_10day\",\n",
    "                                        adjust_for=c(\"fDate\",route_field),# up to 231 levels\n",
    "                                        quick=FALSE,\n",
    "                                        boot.reps=1001,\n",
    "                                        granularity=\"\"){\n",
    "\n",
    "    # build and test the formula \n",
    "    (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "    .updated = as.character(update(FMLA,~.))\n",
    "    if(length(.updated)>1){\n",
    "        .rhs = .updated[3]\n",
    "    }else{\n",
    "        .rhs = strsplit(as.character(update(FMLA,~.)),\" *~ *\")[[1]][2]\n",
    "    }\n",
    "    .terms = strsplit(.rhs,\" *\\\\+ *\")[[1]]\n",
    "    \n",
    "    \n",
    "    .vars = get.vars(rhs(FMLA))\n",
    "    if(any(! (.vars %in% names(data))))\n",
    "           stop(paste(\"missing variable: \",.vars[! (.vars %in% names(data))],collapse=\"\\\\n\"))\n",
    "           \n",
    "    if(any(!(predictors %in% .terms))){\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        cat(\"terms :\\n\")\n",
    "        cat(paste0(.terms,\"\\n\"))\n",
    "        cat(\"\\npredictors :\\n\")\n",
    "        cat(paste0(predictors[!(predictors %in% .terms)],\"\\n\"))\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        stop(\"Bad Predctors\")\n",
    "        \n",
    "    }    \n",
    "    \n",
    "    quick_N <- 5e5\n",
    "    if(quick & data[,.N] > quick_N)\n",
    "        data <- data[sample(.N,quick_N)]\n",
    "    \n",
    "\n",
    "    # FIT THE OLS MODELS\n",
    "    if(TRUE){\n",
    "        \n",
    "        (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "        .lm0 <- lm(FMLA, data = data) # Useful for extracting the R-squared value\n",
    "        LM <- glm(FMLA, data = data) # required for the wild bootstrap\n",
    "    }else{\n",
    "        (FMLA_main <- formula(paste(lhs,'~',paste(c(predictors),collapse=' + '))))\n",
    "        (FMLA_fixed <- formula(paste('~',paste(adjust_for,collapse=' + '))))\n",
    "\n",
    "        # doesn't work (LM <- lm_robust(FMLA_main,  data = data, fixed = FMLA_fixed) )\n",
    "        (LM <- do.call(lm_robust,list(FMLA_main, data = data, fixed = FMLA_fixed,se_type=\"classical\") )) # I hate magic\n",
    "    }\n",
    "    \n",
    "    # SUMMARY OF THE OLS MODEL\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "    cat(\"Model \",model,\":\")\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "   \n",
    "    cat(\"\\n\\nCoefficients from Linear model (adjust_for effects omitted):\\n\")\n",
    "    \n",
    "    # catch the re-ordering of interaction terms introduced by the update(form,dev.new ~ .) call in cluster.wild.glm\n",
    "    tryCatch({\n",
    "        print(coef(summary(LM))[predictors,])    \n",
    "    },error = function(err){\n",
    "        model_coef = dimnames(coef(summary(LM)))[[1]]\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "            print(FMLA)\n",
    "            print(coef(summary(LM)))\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "        cat(\"Missing coefficients:\\n\",\n",
    "            predictors[! predictors %in% model_coef])\n",
    "        cat(\"\\n\\nAvailable coefficients:\\n\")\n",
    "        \n",
    "        print(model_coef)\n",
    "        stop(err)\n",
    "    })\n",
    "\n",
    "    # DO THE WILD BOOTSTRAP\n",
    "    # set.seed(10101)\n",
    "    # cl <-cluster.wild.glm(LM, dat = data, cluster = ~ factor(favorite_route), boot.reps = boot.reps, report=FALSE )\n",
    "\n",
    "    # MAKE THE PRETTY OUTPUT\n",
    "    # without doing the (slow) wild bootstrap\n",
    "    out <- cbind(model=model,\n",
    "                rbind(coef(summary(LM))[predictors,]),\n",
    "                # rbind(cl$ci[predictors,]),\n",
    "                r2= summary(.lm0)$r.squared,\n",
    "                N=data[,.N],\n",
    "                granularity=granularity)\n",
    "\n",
    "    rm(LM); gc() # alas...\n",
    "    # dimnames(out)[[1]] <- predictors\n",
    "    return(out)\n",
    "\n",
    "} "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for table 2\n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 5.267816e-02  1.482744e-03  3.552747e+01 3.301347e-276 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                           </td><td>0.0526781584496653          </td><td>0.00148274449842149         </td><td>35.5274684922087            </td><td>3.30134727985941e-276       </td><td>0.313933117984364           </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                                & 0.0526781584496653               & 0.00148274449842149              & 35.5274684922087                 & 3.30134727985941e-276            & 0.313933117984364                & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1                            | 0.0526781584496653           | 0.00148274449842149          | 35.5274684922087             | 3.30134727985941e-276        | 0.313933117984364            | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 1     0.0526781584496653 0.00148274449842149 35.5274684922087\n",
       "     Pr(>|t|)              r2                N     \n",
       "[1,] 3.30134727985941e-276 0.313933117984364 689102\n",
       "     granularity                 \n",
       "[1,] rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model1_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04761443 0.001989044 23.938343\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.01105660 0.002894922  3.819308\n",
      "                                              Pr(>|t|)\n",
      "imputed_new_buses                        1.377238e-126\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  1.338381e-04\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                           </td><td>0.047614426998541           </td><td>0.00198904442606988         </td><td>23.9383426405521            </td><td>1.3772384801844e-126        </td><td>0.313947641851535           </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                           </td><td>0.0110566008423267          </td><td>0.00289492229332781         </td><td>3.81930833439291            </td><td>0.000133838115167267        </td><td>0.313947641851535           </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                                & 0.047614426998541                & 0.00198904442606988              & 23.9383426405521                 & 1.3772384801844e-126             & 0.313947641851535                & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                & 0.0110566008423267               & 0.00289492229332781              & 3.81930833439291                 & 0.000133838115167267             & 0.313947641851535                & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                            | 0.047614426998541            | 0.00198904442606988          | 23.9383426405521             | 1.3772384801844e-126         | 0.313947641851535            | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                            | 0.0110566008423267           | 0.00289492229332781          | 3.81930833439291             | 0.000133838115167267         | 0.313947641851535            | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate          \n",
       "imputed_new_buses                        2     0.047614426998541 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.0110566008423267\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00198904442606988 23.9383426405521\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00289492229332781 3.81930833439291\n",
       "                                         Pr(>|t|)             r2               \n",
       "imputed_new_buses                        1.3772384801844e-126 0.313947641851535\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.000133838115167267 0.313947641851535\n",
       "                                         N      granularity                 \n",
       "imputed_new_buses                        689102 rider/date/commute [Pre-HOV]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 689102 rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model2_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04439664 0.002618399 16.955642\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.01971082 0.004087730  4.821948\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        1.870814e-64\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 1.422309e-06\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                        </td><td>0.0443966413966682                                       </td><td>0.00261839925440522                                      </td><td>16.9556423918067                                         </td><td>1.87081353519836e-64                                     </td><td>0.340363793247262                                        </td><td>307332                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                        </td><td>0.0197108228940775                                       </td><td>0.00408773039532303                                      </td><td>4.82194787519                                            </td><td>1.42230936474737e-06                                     </td><td>0.340363793247262                                        </td><td>307332                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                                                             & 0.0443966413966682                                            & 0.00261839925440522                                           & 16.9556423918067                                              & 1.87081353519836e-64                                          & 0.340363793247262                                             & 307332                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                             & 0.0197108228940775                                            & 0.00408773039532303                                           & 4.82194787519                                                 & 1.42230936474737e-06                                          & 0.340363793247262                                             & 307332                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                                                         | 0.0443966413966682                                        | 0.00261839925440522                                       | 16.9556423918067                                          | 1.87081353519836e-64                                      | 0.340363793247262                                         | 307332                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                         | 0.0197108228940775                                        | 0.00408773039532303                                       | 4.82194787519                                             | 1.42230936474737e-06                                      | 0.340363793247262                                         | 307332                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate          \n",
       "imputed_new_buses                        3     0.0443966413966682\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     0.0197108228940775\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00261839925440522 16.9556423918067\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00408773039532303 4.82194787519   \n",
       "                                         Pr(>|t|)             r2               \n",
       "imputed_new_buses                        1.87081353519836e-64 0.340363793247262\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 1.42230936474737e-06 0.340363793247262\n",
       "                                         N     \n",
       "imputed_new_buses                        307332\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 307332\n",
       "                                         granularity                                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model3_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (first_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; First stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.049688518 0.002235176 22.230250\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.009463026 0.003465112  2.730944\n",
      "                                              Pr(>|t|)\n",
      "imputed_new_buses                        1.995311e-109\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  6.315563e-03\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                       </td><td>0.0496885184426248                                      </td><td>0.00223517587506173                                     </td><td>22.230249975856                                         </td><td>1.99531099024717e-109                                   </td><td>0.334545171824185                                       </td><td>470230                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                       </td><td>0.00946302618561705                                     </td><td>0.00346511228746171                                     </td><td>2.73094358871383                                        </td><td>0.00631556339535622                                     </td><td>0.334545171824185                                       </td><td>470230                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                                                            & 0.0496885184426248                                           & 0.00223517587506173                                          & 22.230249975856                                              & 1.99531099024717e-109                                        & 0.334545171824185                                            & 470230                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                            & 0.00946302618561705                                          & 0.00346511228746171                                          & 2.73094358871383                                             & 0.00631556339535622                                          & 0.334545171824185                                            & 470230                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                                                        | 0.0496885184426248                                       | 0.00223517587506173                                      | 22.230249975856                                          | 1.99531099024717e-109                                    | 0.334545171824185                                        | 470230                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                        | 0.00946302618561705                                      | 0.00346511228746171                                      | 2.73094358871383                                         | 0.00631556339535622                                      | 0.334545171824185                                        | 470230                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate           \n",
       "imputed_new_buses                        4     0.0496885184426248 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00946302618561705\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00223517587506173 22.230249975856 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00346511228746171 2.73094358871383\n",
       "                                         Pr(>|t|)             \n",
       "imputed_new_buses                        1.99531099024717e-109\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00631556339535622  \n",
       "                                         r2                N     \n",
       "imputed_new_buses                        0.334545171824185 470230\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.334545171824185 470230\n",
       "                                         granularity                                             \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model4_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (last_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 5.974787e-02  2.278580e-03  2.622154e+01 2.036336e-151 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>5                                                     </td><td>0.0597478695314638                                    </td><td>0.00227857974042177                                   </td><td>26.221539879225                                       </td><td>2.03633585740928e-151                                 </td><td>0.302241813081963                                     </td><td>395760                                                </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 5                                                          & 0.0597478695314638                                         & 0.00227857974042177                                        & 26.221539879225                                            & 2.03633585740928e-151                                      & 0.302241813081963                                          & 395760                                                     & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 5                                                      | 0.0597478695314638                                     | 0.00227857974042177                                    | 26.221539879225                                        | 2.03633585740928e-151                                  | 0.302241813081963                                      | 395760                                                 | rider/date/commute [Pre-HOV; Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value        \n",
       "[1,] 5     0.0597478695314638 0.00227857974042177 26.221539879225\n",
       "     Pr(>|t|)              r2                N     \n",
       "[1,] 2.03633585740928e-151 0.302241813081963 395760\n",
       "     granularity                                           \n",
       "[1,] rider/date/commute [Pre-HOV; Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model5_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride >= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  6 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 4.607099e-02  1.886252e-03  2.442463e+01 1.267407e-131 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>6                                                         </td><td>0.046070993459367                                         </td><td>0.00188625156964024                                       </td><td>24.4246282950232                                          </td><td>1.26740674761731e-131                                     </td><td>0.332812477761177                                         </td><td>294658                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 6                                                              & 0.046070993459367                                              & 0.00188625156964024                                            & 24.4246282950232                                               & 1.26740674761731e-131                                          & 0.332812477761177                                              & 294658                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 6                                                          | 0.046070993459367                                          | 0.00188625156964024                                        | 24.4246282950232                                           | 1.26740674761731e-131                                      | 0.332812477761177                                          | 294658                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate          Std. Error          t value         \n",
       "[1,] 6     0.046070993459367 0.00188625156964024 24.4246282950232\n",
       "     Pr(>|t|)              r2                N     \n",
       "[1,] 1.26740674761731e-131 0.332812477761177 294658\n",
       "     granularity                                               \n",
       "[1,] rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model6_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride <= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=6,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Non-Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 2 Summary Statistics \n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                                         </td><td>0.0526781584496653                                        </td><td>0.00148274449842149                                       </td><td>35.5274684922087                                          </td><td>3.30134727985941e-276                                     </td><td>0.313933117984364                                         </td><td>689102                                                    </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                         </td><td>0.047614426998541                                         </td><td>0.00198904442606988                                       </td><td>23.9383426405521                                          </td><td>1.3772384801844e-126                                      </td><td>0.313947641851535                                         </td><td>689102                                                    </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                                                         </td><td>0.0110566008423267                                        </td><td>0.00289492229332781                                       </td><td>3.81930833439291                                          </td><td>0.000133838115167267                                      </td><td>0.313947641851535                                         </td><td>689102                                                    </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                         </td><td>0.0443966413966682                                        </td><td>0.00261839925440522                                       </td><td>16.9556423918067                                          </td><td>1.87081353519836e-64                                      </td><td>0.340363793247262                                         </td><td>307332                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                         </td><td>0.0197108228940775                                        </td><td>0.00408773039532303                                       </td><td>4.82194787519                                             </td><td>1.42230936474737e-06                                      </td><td>0.340363793247262                                         </td><td>307332                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                         </td><td>0.0496885184426248                                        </td><td>0.00223517587506173                                       </td><td>22.230249975856                                           </td><td>1.99531099024717e-109                                     </td><td>0.334545171824185                                         </td><td>470230                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                         </td><td>0.00946302618561705                                       </td><td>0.00346511228746171                                       </td><td>2.73094358871383                                          </td><td>0.00631556339535622                                       </td><td>0.334545171824185                                         </td><td>470230                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row></th><td>5                                                         </td><td>0.0597478695314638                                        </td><td>0.00227857974042177                                       </td><td>26.221539879225                                           </td><td>2.03633585740928e-151                                     </td><td>0.302241813081963                                         </td><td>395760                                                    </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]    </td></tr>\n",
       "\t<tr><th scope=row></th><td>6                                                         </td><td>0.046070993459367                                         </td><td>0.00188625156964024                                       </td><td>24.4246282950232                                          </td><td>1.26740674761731e-131                                     </td><td>0.332812477761177                                         </td><td>294658                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                                              & 0.0526781584496653                                             & 0.00148274449842149                                            & 35.5274684922087                                               & 3.30134727985941e-276                                          & 0.313933117984364                                              & 689102                                                         & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 2                                                              & 0.047614426998541                                              & 0.00198904442606988                                            & 23.9383426405521                                               & 1.3772384801844e-126                                           & 0.313947641851535                                              & 689102                                                         & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                                              & 0.0110566008423267                                             & 0.00289492229332781                                            & 3.81930833439291                                               & 0.000133838115167267                                           & 0.313947641851535                                              & 689102                                                         & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 3                                                              & 0.0443966413966682                                             & 0.00261839925440522                                            & 16.9556423918067                                               & 1.87081353519836e-64                                           & 0.340363793247262                                              & 307332                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                              & 0.0197108228940775                                             & 0.00408773039532303                                            & 4.82194787519                                                  & 1.42230936474737e-06                                           & 0.340363793247262                                              & 307332                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses & 4                                                              & 0.0496885184426248                                             & 0.00223517587506173                                            & 22.230249975856                                                & 1.99531099024717e-109                                          & 0.334545171824185                                              & 470230                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                              & 0.00946302618561705                                            & 0.00346511228746171                                            & 2.73094358871383                                               & 0.00631556339535622                                            & 0.334545171824185                                              & 470230                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\t & 5                                                              & 0.0597478695314638                                             & 0.00227857974042177                                            & 26.221539879225                                                & 2.03633585740928e-151                                          & 0.302241813081963                                              & 395760                                                         & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}    \\\\\n",
       "\t & 6                                                              & 0.046070993459367                                              & 0.00188625156964024                                            & 24.4246282950232                                               & 1.26740674761731e-131                                          & 0.332812477761177                                              & 294658                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                                          | 0.0526781584496653                                         | 0.00148274449842149                                        | 35.5274684922087                                           | 3.30134727985941e-276                                      | 0.313933117984364                                          | 689102                                                     | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 2                                                          | 0.047614426998541                                          | 0.00198904442606988                                        | 23.9383426405521                                           | 1.3772384801844e-126                                       | 0.313947641851535                                          | 689102                                                     | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                                                          | 0.0110566008423267                                         | 0.00289492229332781                                        | 3.81930833439291                                           | 0.000133838115167267                                       | 0.313947641851535                                          | 689102                                                     | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 3                                                          | 0.0443966413966682                                         | 0.00261839925440522                                        | 16.9556423918067                                           | 1.87081353519836e-64                                       | 0.340363793247262                                          | 307332                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                          | 0.0197108228940775                                         | 0.00408773039532303                                        | 4.82194787519                                              | 1.42230936474737e-06                                       | 0.340363793247262                                          | 307332                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses | 4                                                          | 0.0496885184426248                                         | 0.00223517587506173                                        | 22.230249975856                                            | 1.99531099024717e-109                                      | 0.334545171824185                                          | 470230                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                          | 0.00946302618561705                                        | 0.00346511228746171                                        | 2.73094358871383                                           | 0.00631556339535622                                        | 0.334545171824185                                          | 470230                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "|  | 5                                                          | 0.0597478695314638                                         | 0.00227857974042177                                        | 26.221539879225                                            | 2.03633585740928e-151                                      | 0.302241813081963                                          | 395760                                                     | rider/date/commute [Pre-HOV; Seattle preferred riders]     |\n",
       "|  | 6                                                          | 0.046070993459367                                          | 0.00188625156964024                                        | 24.4246282950232                                           | 1.26740674761731e-131                                      | 0.332812477761177                                          | 294658                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate           \n",
       "                                         1     0.0526781584496653 \n",
       "imputed_new_buses                        2     0.047614426998541  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.0110566008423267 \n",
       "imputed_new_buses                        3     0.0443966413966682 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     0.0197108228940775 \n",
       "imputed_new_buses                        4     0.0496885184426248 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00946302618561705\n",
       "                                         5     0.0597478695314638 \n",
       "                                         6     0.046070993459367  \n",
       "                                         Std. Error          t value         \n",
       "                                         0.00148274449842149 35.5274684922087\n",
       "imputed_new_buses                        0.00198904442606988 23.9383426405521\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00289492229332781 3.81930833439291\n",
       "imputed_new_buses                        0.00261839925440522 16.9556423918067\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00408773039532303 4.82194787519   \n",
       "imputed_new_buses                        0.00223517587506173 22.230249975856 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00346511228746171 2.73094358871383\n",
       "                                         0.00227857974042177 26.221539879225 \n",
       "                                         0.00188625156964024 24.4246282950232\n",
       "                                         Pr(>|t|)             \n",
       "                                         3.30134727985941e-276\n",
       "imputed_new_buses                        1.3772384801844e-126 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.000133838115167267 \n",
       "imputed_new_buses                        1.87081353519836e-64 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 1.42230936474737e-06 \n",
       "imputed_new_buses                        1.99531099024717e-109\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00631556339535622  \n",
       "                                         2.03633585740928e-151\n",
       "                                         1.26740674761731e-131\n",
       "                                         r2                N     \n",
       "                                         0.313933117984364 689102\n",
       "imputed_new_buses                        0.313947641851535 689102\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.313947641851535 689102\n",
       "imputed_new_buses                        0.340363793247262 307332\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.340363793247262 307332\n",
       "imputed_new_buses                        0.334545171824185 470230\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.334545171824185 470230\n",
       "                                         0.302241813081963 395760\n",
       "                                         0.332812477761177 294658\n",
       "                                         granularity                                               \n",
       "                                         rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "                                         rider/date/commute [Pre-HOV; Seattle preferred riders]    \n",
       "                                         rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "rbind( table2_model1_pre_HOV,\n",
    "       table2_model2_pre_HOV,\n",
    "       table2_model3_pre_HOV,\n",
    "       table2_model4_pre_HOV,\n",
    "       table2_model5_pre_HOV,\n",
    "       table2_model6_pre_HOV)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>used</th><th scope=col>(Mb)</th><th scope=col>gc trigger</th><th scope=col>(Mb)</th><th scope=col>max used</th><th scope=col>(Mb)</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>Ncells</th><td>  667872 </td><td> 35.7    </td><td>  2310793</td><td> 123.5   </td><td>  8814980</td><td> 470.8   </td></tr>\n",
       "\t<tr><th scope=row>Vcells</th><td>65041151 </td><td>496.3    </td><td>239007949</td><td>1823.5   </td><td>466812403</td><td>3561.5   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllll}\n",
       "  & used & (Mb) & gc trigger & (Mb) & max used & (Mb)\\\\\n",
       "\\hline\n",
       "\tNcells &   667872  &  35.7     &   2310793 &  123.5    &   8814980 &  470.8   \\\\\n",
       "\tVcells & 65041151  & 496.3     & 239007949 & 1823.5    & 466812403 & 3561.5   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | used | (Mb) | gc trigger | (Mb) | max used | (Mb) |\n",
       "|---|---|---|---|---|---|---|\n",
       "| Ncells |   667872  |  35.7     |   2310793 |  123.5    |   8814980 |  470.8    |\n",
       "| Vcells | 65041151  | 496.3     | 239007949 | 1823.5    | 466812403 | 3561.5    |\n",
       "\n"
      ],
      "text/plain": [
       "       used     (Mb)  gc trigger (Mb)   max used  (Mb)  \n",
       "Ncells   667872  35.7   2310793   123.5   8814980  470.8\n",
       "Vcells 65041151 496.3 239007949  1823.5 466812403 3561.5"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1\n",
    "gc()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "8.145358e-03 8.165282e-04 9.975599e+00 1.952366e-23 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                   </td><td>0.00814535842377904 </td><td>0.000816528232731527</td><td>9.97559924723046    </td><td>1.95236591522484e-23</td><td>0.34749417401812    </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                    & 0.00814535842377904  & 0.000816528232731527 & 9.97559924723046     & 1.95236591522484e-23 & 0.34749417401812     & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1                    | 0.00814535842377904  | 0.000816528232731527 | 9.97559924723046     | 1.95236591522484e-23 | 0.34749417401812     | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate            Std. Error           t value         \n",
       "[1,] 1     0.00814535842377904 0.000816528232731527 9.97559924723046\n",
       "     Pr(>|t|)             r2               N       granularity       \n",
       "[1,] 1.95236591522484e-23 0.34749417401812 1562314 rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model1 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=1,\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "post_hov:IsRouteSeattle_10_ride                 0.0079671424 0.001464451\n",
      "is_peak_10_ride                                 0.0002857328 0.001204495\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride          0.0083323565 0.001548633\n",
      "post_hov:is_peak_10_ride                        0.0021276809 0.001621872\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.0004544467 0.002088067\n",
      "                                                  t value     Pr(>|t|)\n",
      "post_hov:IsRouteSeattle_10_ride                 5.4403593 5.318116e-08\n",
      "is_peak_10_ride                                 0.2372222 8.124845e-01\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride          5.3804574 7.430745e-08\n",
      "post_hov:is_peak_10_ride                        1.3118669 1.895652e-01\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.2176399 8.277097e-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>2                   </td><td>0.00796714237875826 </td><td>0.00146445149414994 </td><td>5.44035934995776    </td><td>5.31811585004826e-08</td><td>0.347587359416293   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                   </td><td>0.000285732800606085</td><td>0.0012044945663228  </td><td>0.237222158235547   </td><td>0.81248447818932    </td><td>0.347587359416293   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                   </td><td>0.00833235654072214 </td><td>0.00154863348049986 </td><td>5.38045744563953    </td><td>7.4307446298797e-08 </td><td>0.347587359416293   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>post_hov:is_peak_10_ride</th><td>2                   </td><td>0.00212768088189848 </td><td>0.00162187247983776 </td><td>1.31186693673433    </td><td>0.189565227837086   </td><td>0.347587359416293   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                   </td><td>0.000454446662323543</td><td>0.00208806717081334 </td><td>0.217639867469651   </td><td>0.82770974765908    </td><td>0.347587359416293   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 2                    & 0.00796714237875826  & 0.00146445149414994  & 5.44035934995776     & 5.31811585004826e-08 & 0.347587359416293    & 1562314              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                    & 0.000285732800606085 & 0.0012044945663228   & 0.237222158235547    & 0.81248447818932     & 0.347587359416293    & 1562314              & rider/date/commute  \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                    & 0.00833235654072214  & 0.00154863348049986  & 5.38045744563953     & 7.4307446298797e-08  & 0.347587359416293    & 1562314              & rider/date/commute  \\\\\n",
       "\tpost\\_hov:is\\_peak\\_10\\_ride & 2                    & 0.00212768088189848  & 0.00162187247983776  & 1.31186693673433     & 0.189565227837086    & 0.347587359416293    & 1562314              & rider/date/commute  \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                    & 0.000454446662323543 & 0.00208806717081334  & 0.217639867469651    & 0.82770974765908     & 0.347587359416293    & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 2                    | 0.00796714237875826  | 0.00146445149414994  | 5.44035934995776     | 5.31811585004826e-08 | 0.347587359416293    | 1562314              | rider/date/commute   |\n",
       "| is_peak_10_ride | 2                    | 0.000285732800606085 | 0.0012044945663228   | 0.237222158235547    | 0.81248447818932     | 0.347587359416293    | 1562314              | rider/date/commute   |\n",
       "| IsRouteSeattle_10_ride:is_peak_10_ride | 2                    | 0.00833235654072214  | 0.00154863348049986  | 5.38045744563953     | 7.4307446298797e-08  | 0.347587359416293    | 1562314              | rider/date/commute   |\n",
       "| post_hov:is_peak_10_ride | 2                    | 0.00212768088189848  | 0.00162187247983776  | 1.31186693673433     | 0.189565227837086    | 0.347587359416293    | 1562314              | rider/date/commute   |\n",
       "| post_hov:IsRouteSeattle_10_ride:is_peak_10_ride | 2                    | 0.000454446662323543 | 0.00208806717081334  | 0.217639867469651    | 0.82770974765908     | 0.347587359416293    | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model Estimate            \n",
       "post_hov:IsRouteSeattle_10_ride                 2     0.00796714237875826 \n",
       "is_peak_10_ride                                 2     0.000285732800606085\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2     0.00833235654072214 \n",
       "post_hov:is_peak_10_ride                        2     0.00212768088189848 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 2     0.000454446662323543\n",
       "                                                Std. Error         \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00146445149414994\n",
       "is_peak_10_ride                                 0.0012044945663228 \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.00154863348049986\n",
       "post_hov:is_peak_10_ride                        0.00162187247983776\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00208806717081334\n",
       "                                                t value          \n",
       "post_hov:IsRouteSeattle_10_ride                 5.44035934995776 \n",
       "is_peak_10_ride                                 0.237222158235547\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          5.38045744563953 \n",
       "post_hov:is_peak_10_ride                        1.31186693673433 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.217639867469651\n",
       "                                                Pr(>|t|)            \n",
       "post_hov:IsRouteSeattle_10_ride                 5.31811585004826e-08\n",
       "is_peak_10_ride                                 0.81248447818932    \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          7.4307446298797e-08 \n",
       "post_hov:is_peak_10_ride                        0.189565227837086   \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.82770974765908    \n",
       "                                                r2                N      \n",
       "post_hov:IsRouteSeattle_10_ride                 0.347587359416293 1562314\n",
       "is_peak_10_ride                                 0.347587359416293 1562314\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.347587359416293 1562314\n",
       "post_hov:is_peak_10_ride                        0.347587359416293 1562314\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.347587359416293 1562314\n",
       "                                                granularity       \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute\n",
       "is_peak_10_ride                                 rider/date/commute\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          rider/date/commute\n",
       "post_hov:is_peak_10_ride                        rider/date/commute\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\",\n",
    "                                        \"is_peak_10_ride\",\n",
    "                                        \"IsRouteSeattle_10_ride:is_peak_10_ride\",\n",
    "                                        \"post_hov:is_peak_10_ride\",\n",
    "                                        \"post_hov:IsRouteSeattle_10_ride:is_peak_10_ride\"\n",
    "                                ),\n",
    "                        model=2,\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.033419e-02 1.176793e-03 8.781651e+00 1.614499e-18 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3                                              </td><td>0.0103341888162002                             </td><td>0.0011767933867184                             </td><td>8.78165099569267                               </td><td>1.61449880299865e-18                           </td><td>0.364963972744727                              </td><td>688058                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 3                                                   & 0.0103341888162002                                  & 0.0011767933867184                                  & 8.78165099569267                                    & 1.61449880299865e-18                                & 0.364963972744727                                   & 688058                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 3                                               | 0.0103341888162002                              | 0.0011767933867184                              | 8.78165099569267                                | 1.61449880299865e-18                            | 0.364963972744727                               | 688058                                          | rider/date/commute [first stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error         t value         \n",
       "[1,] 3     0.0103341888162002 0.0011767933867184 8.78165099569267\n",
       "     Pr(>|t|)             r2                N     \n",
       "[1,] 1.61449880299865e-18 0.364963972744727 688058\n",
       "     granularity                                    \n",
       "[1,] rider/date/commute [first stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model3 = fit_ridership_logit_models(data = commute_ride_data[first_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=3,\n",
    "                        granularity=\"rider/date/commute [first stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "6.615179e-03 9.843159e-04 6.720586e+00 1.810857e-11 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>4                                             </td><td>0.00661517940363815                           </td><td>0.00098431590064777                           </td><td>6.72058573805905                              </td><td>1.81085730798847e-11                          </td><td>0.362381364112479                             </td><td>1068360                                       </td><td>rider/date/commute [last stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 4                                                  & 0.00661517940363815                                & 0.00098431590064777                                & 6.72058573805905                                   & 1.81085730798847e-11                               & 0.362381364112479                                  & 1068360                                            & rider/date/commute {[}last stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 4                                              | 0.00661517940363815                            | 0.00098431590064777                            | 6.72058573805905                               | 1.81085730798847e-11                           | 0.362381364112479                              | 1068360                                        | rider/date/commute [last stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate            Std. Error          t value         \n",
       "[1,] 4     0.00661517940363815 0.00098431590064777 6.72058573805905\n",
       "     Pr(>|t|)             r2                N      \n",
       "[1,] 1.81085730798847e-11 0.362381364112479 1068360\n",
       "     granularity                                   \n",
       "[1,] rider/date/commute [last stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model4 = fit_ridership_logit_models(data = commute_ride_data[last_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=4,\n",
    "                        granularity=\"rider/date/commute [last stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.003799257 0.001262081 3.010311717 0.002609883 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>5                  </td><td>0.00379925654544779</td><td>0.00126208077541554</td><td>3.01031171653564   </td><td>0.00260988266348954</td><td>0.352607027348902  </td><td>759650             </td><td>ride/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 5                   & 0.00379925654544779 & 0.00126208077541554 & 3.01031171653564    & 0.00260988266348954 & 0.352607027348902   & 759650              & ride/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 5                   | 0.00379925654544779 | 0.00126208077541554 | 3.01031171653564    | 0.00260988266348954 | 0.352607027348902   | 759650              | ride/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate            Std. Error          t value         \n",
       "[1,] 5     0.00379925654544779 0.00126208077541554 3.01031171653564\n",
       "     Pr(>|t|)            r2                N      granularity      \n",
       "[1,] 0.00260988266348954 0.352607027348902 759650 ride/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model5 = fit_ridership_logit_models(data = commute_ride_data[date >= as.Date(\"2016-03-01\") & \n",
    "                                                        date < as.Date(\"2016-07-01\")],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=5,\n",
    "                        granularity=\"ride/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 3 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                              </td><td>0.00814535842377904                            </td><td>0.000816528232731527                           </td><td>9.97559924723046                               </td><td>1.95236591522484e-23                           </td><td>0.34749417401812                               </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>2                                              </td><td>0.00796714237875826                            </td><td>0.00146445149414994                            </td><td>5.44035934995776                               </td><td>5.31811585004826e-08                           </td><td>0.347587359416293                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                                              </td><td>0.000285732800606085                           </td><td>0.0012044945663228                             </td><td>0.237222158235547                              </td><td>0.81248447818932                               </td><td>0.347587359416293                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.00833235654072214                            </td><td>0.00154863348049986                            </td><td>5.38045744563953                               </td><td>7.4307446298797e-08                            </td><td>0.347587359416293                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:is_peak_10_ride</th><td>2                                              </td><td>0.00212768088189848                            </td><td>0.00162187247983776                            </td><td>1.31186693673433                               </td><td>0.189565227837086                              </td><td>0.347587359416293                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.000454446662323543                           </td><td>0.00208806717081334                            </td><td>0.217639867469651                              </td><td>0.82770974765908                               </td><td>0.347587359416293                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row></th><td>3                                              </td><td>0.0103341888162002                             </td><td>0.0011767933867184                             </td><td>8.78165099569267                               </td><td>1.61449880299865e-18                           </td><td>0.364963972744727                              </td><td>688058                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "\t<tr><th scope=row></th><td>4                                              </td><td>0.00661517940363815                            </td><td>0.00098431590064777                            </td><td>6.72058573805905                               </td><td>1.81085730798847e-11                           </td><td>0.362381364112479                              </td><td>1068360                                        </td><td>rider/date/commute [last stop prefered riders] </td></tr>\n",
       "\t<tr><th scope=row></th><td>5                                              </td><td>0.00379925654544779                            </td><td>0.00126208077541554                            </td><td>3.01031171653564                               </td><td>0.00260988266348954                            </td><td>0.352607027348902                              </td><td>759650                                         </td><td>ride/date/commute                              </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                               & 0.00814535842377904                             & 0.000816528232731527                            & 9.97559924723046                                & 1.95236591522484e-23                            & 0.34749417401812                                & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 2                                               & 0.00796714237875826                             & 0.00146445149414994                             & 5.44035934995776                                & 5.31811585004826e-08                            & 0.347587359416293                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                                               & 0.000285732800606085                            & 0.0012044945663228                              & 0.237222158235547                               & 0.81248447818932                                & 0.347587359416293                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.00833235654072214                             & 0.00154863348049986                             & 5.38045744563953                                & 7.4307446298797e-08                             & 0.347587359416293                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:is\\_peak\\_10\\_ride & 2                                               & 0.00212768088189848                             & 0.00162187247983776                             & 1.31186693673433                                & 0.189565227837086                               & 0.347587359416293                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.000454446662323543                            & 0.00208806717081334                             & 0.217639867469651                               & 0.82770974765908                                & 0.347587359416293                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\t & 3                                                   & 0.0103341888162002                                  & 0.0011767933867184                                  & 8.78165099569267                                    & 1.61449880299865e-18                                & 0.364963972744727                                   & 688058                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\t & 4                                                   & 0.00661517940363815                                 & 0.00098431590064777                                 & 6.72058573805905                                    & 1.81085730798847e-11                                & 0.362381364112479                                   & 1068360                                             & rider/date/commute {[}last stop prefered riders{]} \\\\\n",
       "\t & 5                                               & 0.00379925654544779                             & 0.00126208077541554                             & 3.01031171653564                                & 0.00260988266348954                             & 0.352607027348902                               & 759650                                          & ride/date/commute                              \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                               | 0.00814535842377904                             | 0.000816528232731527                            | 9.97559924723046                                | 1.95236591522484e-23                            | 0.34749417401812                                | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 2                                               | 0.00796714237875826                             | 0.00146445149414994                             | 5.44035934995776                                | 5.31811585004826e-08                            | 0.347587359416293                               | 1562314                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride | 2                                               | 0.000285732800606085                            | 0.0012044945663228                              | 0.237222158235547                               | 0.81248447818932                                | 0.347587359416293                               | 1562314                                         | rider/date/commute                              |\n",
       "| IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.00833235654072214                             | 0.00154863348049986                             | 5.38045744563953                                | 7.4307446298797e-08                             | 0.347587359416293                               | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:is_peak_10_ride | 2                                               | 0.00212768088189848                             | 0.00162187247983776                             | 1.31186693673433                                | 0.189565227837086                               | 0.347587359416293                               | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.000454446662323543                            | 0.00208806717081334                             | 0.217639867469651                               | 0.82770974765908                                | 0.347587359416293                               | 1562314                                         | rider/date/commute                              |\n",
       "|  | 3                                               | 0.0103341888162002                              | 0.0011767933867184                              | 8.78165099569267                                | 1.61449880299865e-18                            | 0.364963972744727                               | 688058                                          | rider/date/commute [first stop prefered riders] |\n",
       "|  | 4                                               | 0.00661517940363815                             | 0.00098431590064777                             | 6.72058573805905                                | 1.81085730798847e-11                            | 0.362381364112479                               | 1068360                                         | rider/date/commute [last stop prefered riders]  |\n",
       "|  | 5                                               | 0.00379925654544779                             | 0.00126208077541554                             | 3.01031171653564                                | 0.00260988266348954                             | 0.352607027348902                               | 759650                                          | ride/date/commute                               |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model Estimate            \n",
       "                                                1     0.00814535842377904 \n",
       "post_hov:IsRouteSeattle_10_ride                 2     0.00796714237875826 \n",
       "is_peak_10_ride                                 2     0.000285732800606085\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2     0.00833235654072214 \n",
       "post_hov:is_peak_10_ride                        2     0.00212768088189848 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 2     0.000454446662323543\n",
       "                                                3     0.0103341888162002  \n",
       "                                                4     0.00661517940363815 \n",
       "                                                5     0.00379925654544779 \n",
       "                                                Std. Error          \n",
       "                                                0.000816528232731527\n",
       "post_hov:IsRouteSeattle_10_ride                 0.00146445149414994 \n",
       "is_peak_10_ride                                 0.0012044945663228  \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.00154863348049986 \n",
       "post_hov:is_peak_10_ride                        0.00162187247983776 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00208806717081334 \n",
       "                                                0.0011767933867184  \n",
       "                                                0.00098431590064777 \n",
       "                                                0.00126208077541554 \n",
       "                                                t value          \n",
       "                                                9.97559924723046 \n",
       "post_hov:IsRouteSeattle_10_ride                 5.44035934995776 \n",
       "is_peak_10_ride                                 0.237222158235547\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          5.38045744563953 \n",
       "post_hov:is_peak_10_ride                        1.31186693673433 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.217639867469651\n",
       "                                                8.78165099569267 \n",
       "                                                6.72058573805905 \n",
       "                                                3.01031171653564 \n",
       "                                                Pr(>|t|)            \n",
       "                                                1.95236591522484e-23\n",
       "post_hov:IsRouteSeattle_10_ride                 5.31811585004826e-08\n",
       "is_peak_10_ride                                 0.81248447818932    \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          7.4307446298797e-08 \n",
       "post_hov:is_peak_10_ride                        0.189565227837086   \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.82770974765908    \n",
       "                                                1.61449880299865e-18\n",
       "                                                1.81085730798847e-11\n",
       "                                                0.00260988266348954 \n",
       "                                                r2                N      \n",
       "                                                0.34749417401812  1562314\n",
       "post_hov:IsRouteSeattle_10_ride                 0.347587359416293 1562314\n",
       "is_peak_10_ride                                 0.347587359416293 1562314\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.347587359416293 1562314\n",
       "post_hov:is_peak_10_ride                        0.347587359416293 1562314\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.347587359416293 1562314\n",
       "                                                0.364963972744727 688058 \n",
       "                                                0.362381364112479 1068360\n",
       "                                                0.352607027348902 759650 \n",
       "                                                granularity                                    \n",
       "                                                rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "is_peak_10_ride                                 rider/date/commute                             \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          rider/date/commute                             \n",
       "post_hov:is_peak_10_ride                        rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride rider/date/commute                             \n",
       "                                                rider/date/commute [first stop prefered riders]\n",
       "                                                rider/date/commute [last stop prefered riders] \n",
       "                                                ride/date/commute                              "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1\n",
    "rbind( table3_model1,\n",
    "       table3_model2,\n",
    "       table3_model3,\n",
    "       table3_model4,\n",
    "       table3_model5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.009313578 0.004455380 2.090411594 0.036583679 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                                                </td><td>0.00931357756704925                              </td><td>0.00445537978838421                              </td><td>2.09041159439001                                 </td><td>0.0365836787311989                               </td><td>0.377208112151117                                </td><td>88994                                            </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                                                     & 0.00931357756704925                                   & 0.00445537978838421                                   & 2.09041159439001                                      & 0.0365836787311989                                    & 0.377208112151117                                     & 88994                                                 & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1                                                 | 0.00931357756704925                               | 0.00445537978838421                               | 2.09041159439001                                  | 0.0365836787311989                                | 0.377208112151117                                 | 88994                                             | rider/date/commute [Single Stop Preferred Riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate            Std. Error          t value         \n",
       "[1,] 1     0.00931357756704925 0.00445537978838421 2.09041159439001\n",
       "     Pr(>|t|)           r2                N    \n",
       "[1,] 0.0365836787311989 0.377208112151117 88994\n",
       "     granularity                                      \n",
       "[1,] rider/date/commute [Single Stop Preferred Riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M1 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV) & (single_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                           \"f_favorite_route\" ),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Single Stop Preferred Riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                         Estimate  Std. Error  t value\n",
      "imputed_new_buses                     0.002115268 0.001861147 1.136540\n",
      "imputed_new_buses:single_stop_10_ride 0.005216440 0.002171855 2.401837\n",
      "                                        Pr(>|t|)\n",
      "imputed_new_buses                     0.25573102\n",
      "imputed_new_buses:single_stop_10_ride 0.01631325\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                  </td><td>0.00211526784534133</td><td>0.00186114683008929</td><td>1.13654001454568   </td><td>0.255731024058471  </td><td>0.319809286311396  </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                  </td><td>0.00521643991356266</td><td>0.00217185454431983</td><td>2.40183668248203   </td><td>0.0163132527431281 </td><td>0.319809286311396  </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                   & 0.00211526784534133 & 0.00186114683008929 & 1.13654001454568    & 0.255731024058471   & 0.319809286311396   & 689102              & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                   & 0.00521643991356266 & 0.00217185454431983 & 2.40183668248203    & 0.0163132527431281  & 0.319809286311396   & 689102              & rider/date/commute \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                   | 0.00211526784534133 | 0.00186114683008929 | 1.13654001454568    | 0.255731024058471   | 0.319809286311396   | 689102              | rider/date/commute  |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                   | 0.00521643991356266 | 0.00217185454431983 | 2.40183668248203    | 0.0163132527431281  | 0.319809286311396   | 689102              | rider/date/commute  |\n",
       "\n"
      ],
      "text/plain": [
       "                                      model Estimate           \n",
       "imputed_new_buses                     2     0.00211526784534133\n",
       "imputed_new_buses:single_stop_10_ride 2     0.00521643991356266\n",
       "                                      Std. Error          t value         \n",
       "imputed_new_buses                     0.00186114683008929 1.13654001454568\n",
       "imputed_new_buses:single_stop_10_ride 0.00217185454431983 2.40183668248203\n",
       "                                      Pr(>|t|)           r2               \n",
       "imputed_new_buses                     0.255731024058471  0.319809286311396\n",
       "imputed_new_buses:single_stop_10_ride 0.0163132527431281 0.319809286311396\n",
       "                                      N      granularity       \n",
       "imputed_new_buses                     689102 rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride 689102 rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:single_stop_10_ride\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                Estimate  Std. Error    t value\n",
      "imputed_new_buses                             0.06285117 0.065730225  0.9561989\n",
      "Is405North_10_ride:I405HOV                    0.05578141 0.008109889  6.8781966\n",
      "imputed_new_buses:I405HOV                    -0.05436540 0.065499599 -0.8300113\n",
      "imputed_new_buses:Is405North_10_ride          0.10642284 0.087547980  1.2155945\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.13615843 0.087509338 -1.5559303\n",
      "                                                 Pr(>|t|)\n",
      "imputed_new_buses                            3.389721e-01\n",
      "Is405North_10_ride:I405HOV                   6.066631e-12\n",
      "imputed_new_buses:I405HOV                    4.065327e-01\n",
      "imputed_new_buses:Is405North_10_ride         2.241399e-01\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV 1.197251e-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                   </td><td>0.0628511723878487  </td><td>0.0657302253213042  </td><td>0.956198949275132   </td><td>0.338972066240506   </td><td>0.319889816181573   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                   </td><td>0.0557814133181326  </td><td>0.00810988938632222 </td><td>6.87819656482751    </td><td>6.06663120489689e-12</td><td>0.319889816181573   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                   </td><td>-0.0543654048593643 </td><td>0.0654995990023083  </td><td>-0.830011262472742  </td><td>0.406532703630587   </td><td>0.319889816181573   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                   </td><td>0.106422839326307   </td><td>0.0875479801184227  </td><td>1.21559445668938    </td><td>0.224139863421881   </td><td>0.319889816181573   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                   </td><td>-0.136158432437297  </td><td>0.0875093383844803  </td><td>-1.55593031499189   </td><td>0.119725123167939   </td><td>0.319889816181573   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                    & 0.0628511723878487   & 0.0657302253213042   & 0.956198949275132    & 0.338972066240506    & 0.319889816181573    & 689102               & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                    & 0.0557814133181326   & 0.00810988938632222  & 6.87819656482751     & 6.06663120489689e-12 & 0.319889816181573    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                    & -0.0543654048593643  & 0.0654995990023083   & -0.830011262472742   & 0.406532703630587    & 0.319889816181573    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                    & 0.106422839326307    & 0.0875479801184227   & 1.21559445668938     & 0.224139863421881    & 0.319889816181573    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                    & -0.136158432437297   & 0.0875093383844803   & -1.55593031499189    & 0.119725123167939    & 0.319889816181573    & 689102               & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                    | 0.0628511723878487   | 0.0657302253213042   | 0.956198949275132    | 0.338972066240506    | 0.319889816181573    | 689102               | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 3                    | 0.0557814133181326   | 0.00810988938632222  | 6.87819656482751     | 6.06663120489689e-12 | 0.319889816181573    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:I405HOV | 3                    | -0.0543654048593643  | 0.0654995990023083   | -0.830011262472742   | 0.406532703630587    | 0.319889816181573    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                    | 0.106422839326307    | 0.0875479801184227   | 1.21559445668938     | 0.224139863421881    | 0.319889816181573    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                    | -0.136158432437297   | 0.0875093383844803   | -1.55593031499189    | 0.119725123167939    | 0.319889816181573    | 689102               | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                             model Estimate           \n",
       "imputed_new_buses                            3     0.0628511723878487 \n",
       "Is405North_10_ride:I405HOV                   3     0.0557814133181326 \n",
       "imputed_new_buses:I405HOV                    3     -0.0543654048593643\n",
       "imputed_new_buses:Is405North_10_ride         3     0.106422839326307  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 3     -0.136158432437297 \n",
       "                                             Std. Error         \n",
       "imputed_new_buses                            0.0657302253213042 \n",
       "Is405North_10_ride:I405HOV                   0.00810988938632222\n",
       "imputed_new_buses:I405HOV                    0.0654995990023083 \n",
       "imputed_new_buses:Is405North_10_ride         0.0875479801184227 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.0875093383844803 \n",
       "                                             t value           \n",
       "imputed_new_buses                            0.956198949275132 \n",
       "Is405North_10_ride:I405HOV                   6.87819656482751  \n",
       "imputed_new_buses:I405HOV                    -0.830011262472742\n",
       "imputed_new_buses:Is405North_10_ride         1.21559445668938  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV -1.55593031499189 \n",
       "                                             Pr(>|t|)            \n",
       "imputed_new_buses                            0.338972066240506   \n",
       "Is405North_10_ride:I405HOV                   6.06663120489689e-12\n",
       "imputed_new_buses:I405HOV                    0.406532703630587   \n",
       "imputed_new_buses:Is405North_10_ride         0.224139863421881   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.119725123167939   \n",
       "                                             r2                N     \n",
       "imputed_new_buses                            0.319889816181573 689102\n",
       "Is405North_10_ride:I405HOV                   0.319889816181573 689102\n",
       "imputed_new_buses:I405HOV                    0.319889816181573 689102\n",
       "imputed_new_buses:Is405North_10_ride         0.319889816181573 689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.319889816181573 689102\n",
       "                                             granularity       \n",
       "imputed_new_buses                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:I405HOV                    rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride         rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M3 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "imputed_new_buses                               0.0085334766 0.002033886\n",
      "imputed_new_buses:single_stop_10_ride          -0.0006245411 0.002719838\n",
      "Is405North_10_ride:I405HOV                      0.0400377259 0.006447638\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -0.0298398709 0.003591420\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV  0.0155669800 0.004041421\n",
      "                                                  t value     Pr(>|t|)\n",
      "imputed_new_buses                               4.1956520 2.721218e-05\n",
      "imputed_new_buses:single_stop_10_ride          -0.2296244 8.183837e-01\n",
      "Is405North_10_ride:I405HOV                      6.2096734 5.312495e-10\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -8.3086559 9.696448e-17\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV  3.8518578 1.172357e-04\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                   </td><td>0.00853347664041471 </td><td>0.00203388572695324 </td><td>4.19565196182278    </td><td>2.72121795528025e-05</td><td>0.319903797330774   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                   </td><td>-0.00062454108055395</td><td>0.00271983779498736 </td><td>-0.22962438484566   </td><td>0.81838372493912    </td><td>0.319903797330774   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                   </td><td>0.0400377259018087  </td><td>0.00644763793034833 </td><td>6.20967342371312    </td><td>5.31249524023138e-10</td><td>0.319903797330774   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.0298398708671568 </td><td>0.00359141973270209 </td><td>-8.30865593220597   </td><td>9.6964482878064e-17 </td><td>0.319903797330774   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                   </td><td>0.0155669799634182  </td><td>0.00404142125154769 </td><td>3.85185779815868    </td><td>0.000117235692783138</td><td>0.319903797330774   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                    & 0.00853347664041471  & 0.00203388572695324  & 4.19565196182278     & 2.72121795528025e-05 & 0.319903797330774    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                    & -0.00062454108055395 & 0.00271983779498736  & -0.22962438484566    & 0.81838372493912     & 0.319903797330774    & 689102               & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                    & 0.0400377259018087   & 0.00644763793034833  & 6.20967342371312     & 5.31249524023138e-10 & 0.319903797330774    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                    & -0.0298398708671568  & 0.00359141973270209  & -8.30865593220597    & 9.6964482878064e-17  & 0.319903797330774    & 689102               & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                    & 0.0155669799634182   & 0.00404142125154769  & 3.85185779815868     & 0.000117235692783138 & 0.319903797330774    & 689102               & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                    | 0.00853347664041471  | 0.00203388572695324  | 4.19565196182278     | 2.72121795528025e-05 | 0.319903797330774    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                    | -0.00062454108055395 | 0.00271983779498736  | -0.22962438484566    | 0.81838372493912     | 0.319903797330774    | 689102               | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 4                    | 0.0400377259018087   | 0.00644763793034833  | 6.20967342371312     | 5.31249524023138e-10 | 0.319903797330774    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                    | -0.0298398708671568  | 0.00359141973270209  | -8.30865593220597    | 9.6964482878064e-17  | 0.319903797330774    | 689102               | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                    | 0.0155669799634182   | 0.00404142125154769  | 3.85185779815868     | 0.000117235692783138 | 0.319903797330774    | 689102               | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                               model Estimate            \n",
       "imputed_new_buses                              4     0.00853347664041471 \n",
       "imputed_new_buses:single_stop_10_ride          4     -0.00062454108055395\n",
       "Is405North_10_ride:I405HOV                     4     0.0400377259018087  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   4     -0.0298398708671568 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 4     0.0155669799634182  \n",
       "                                               Std. Error         \n",
       "imputed_new_buses                              0.00203388572695324\n",
       "imputed_new_buses:single_stop_10_ride          0.00271983779498736\n",
       "Is405North_10_ride:I405HOV                     0.00644763793034833\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.00359141973270209\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.00404142125154769\n",
       "                                               t value          \n",
       "imputed_new_buses                              4.19565196182278 \n",
       "imputed_new_buses:single_stop_10_ride          -0.22962438484566\n",
       "Is405North_10_ride:I405HOV                     6.20967342371312 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -8.30865593220597\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 3.85185779815868 \n",
       "                                               Pr(>|t|)            \n",
       "imputed_new_buses                              2.72121795528025e-05\n",
       "imputed_new_buses:single_stop_10_ride          0.81838372493912    \n",
       "Is405North_10_ride:I405HOV                     5.31249524023138e-10\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   9.6964482878064e-17 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.000117235692783138\n",
       "                                               r2                N     \n",
       "imputed_new_buses                              0.319903797330774 689102\n",
       "imputed_new_buses:single_stop_10_ride          0.319903797330774 689102\n",
       "Is405North_10_ride:I405HOV                     0.319903797330774 689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.319903797330774 689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.319903797330774 689102\n",
       "                                               granularity       \n",
       "imputed_new_buses                              rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride          rider/date/commute\n",
       "Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M4 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                                     Estimate\n",
      "imputed_new_buses                                                 0.008163463\n",
      "imputed_new_buses:single_stop_10_ride                             0.001369437\n",
      "Is405North_10_ride:I405HOV                                        0.035454733\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.024289512\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    0.037674036\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.026786439\n",
      "                                                                  Std. Error\n",
      "imputed_new_buses                                                0.002038908\n",
      "imputed_new_buses:single_stop_10_ride                            0.002827104\n",
      "Is405North_10_ride:I405HOV                                       0.006686945\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     0.004184357\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.009459256\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.010362753\n",
      "                                                                    t value\n",
      "imputed_new_buses                                                 4.0038399\n",
      "imputed_new_buses:single_stop_10_ride                             0.4843958\n",
      "Is405North_10_ride:I405HOV                                        5.3020825\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -5.8048375\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    3.9827693\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -2.5848767\n",
      "                                                                     Pr(>|t|)\n",
      "imputed_new_buses                                                6.232906e-05\n",
      "imputed_new_buses:single_stop_10_ride                            6.281052e-01\n",
      "Is405North_10_ride:I405HOV                                       1.145242e-07\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     6.445658e-09\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   6.812385e-05\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 9.741585e-03\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                   </td><td>0.00816346309887731 </td><td>0.00203890845192655 </td><td>4.00383994247692    </td><td>6.23290612101973e-05</td><td>0.319910393524676   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                   </td><td>0.00136943719761286 </td><td>0.00282710402757675 </td><td>0.484395757727626   </td><td>0.628105182568772   </td><td>0.319910393524676   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.035454732615988   </td><td>0.00668694477164967 </td><td>5.30208246467113    </td><td>1.14524242848869e-07</td><td>0.319910393524676   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0242895117885626 </td><td>0.00418435691532861 </td><td>-5.80483746488798   </td><td>6.44565818674655e-09</td><td>0.319910393524676   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.0376740364022946  </td><td>0.00945925646818754 </td><td>3.98276931479723    </td><td>6.81238545722762e-05</td><td>0.319910393524676   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0267864394059024 </td><td>0.0103627530703509  </td><td>-2.58487674308692   </td><td>0.00974158503900379 </td><td>0.319910393524676   </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                    & 0.00816346309887731  & 0.00203890845192655  & 4.00383994247692     & 6.23290612101973e-05 & 0.319910393524676    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                    & 0.00136943719761286  & 0.00282710402757675  & 0.484395757727626    & 0.628105182568772    & 0.319910393524676    & 689102               & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                    & 0.035454732615988    & 0.00668694477164967  & 5.30208246467113     & 1.14524242848869e-07 & 0.319910393524676    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                    & -0.0242895117885626  & 0.00418435691532861  & -5.80483746488798    & 6.44565818674655e-09 & 0.319910393524676    & 689102               & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & 0.0376740364022946   & 0.00945925646818754  & 3.98276931479723     & 6.81238545722762e-05 & 0.319910393524676    & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & -0.0267864394059024  & 0.0103627530703509   & -2.58487674308692    & 0.00974158503900379  & 0.319910393524676    & 689102               & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                    | 0.00816346309887731  | 0.00203890845192655  | 4.00383994247692     | 6.23290612101973e-05 | 0.319910393524676    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                    | 0.00136943719761286  | 0.00282710402757675  | 0.484395757727626    | 0.628105182568772    | 0.319910393524676    | 689102               | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 5                    | 0.035454732615988    | 0.00668694477164967  | 5.30208246467113     | 1.14524242848869e-07 | 0.319910393524676    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                    | -0.0242895117885626  | 0.00418435691532861  | -5.80483746488798    | 6.44565818674655e-09 | 0.319910393524676    | 689102               | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | 0.0376740364022946   | 0.00945925646818754  | 3.98276931479723     | 6.81238545722762e-05 | 0.319910393524676    | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | -0.0267864394059024  | 0.0103627530703509   | -2.58487674308692    | 0.00974158503900379  | 0.319910393524676    | 689102               | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate           \n",
       "imputed_new_buses                                                0.00816346309887731\n",
       "imputed_new_buses:single_stop_10_ride                            0.00136943719761286\n",
       "Is405North_10_ride:I405HOV                                       0.035454732615988  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0242895117885626\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0376740364022946 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0267864394059024\n",
       "                                                                 Std. Error         \n",
       "imputed_new_buses                                                0.00203890845192655\n",
       "imputed_new_buses:single_stop_10_ride                            0.00282710402757675\n",
       "Is405North_10_ride:I405HOV                                       0.00668694477164967\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.00418435691532861\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00945925646818754\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.0103627530703509 \n",
       "                                                                 t value          \n",
       "imputed_new_buses                                                4.00383994247692 \n",
       "imputed_new_buses:single_stop_10_ride                            0.484395757727626\n",
       "Is405North_10_ride:I405HOV                                       5.30208246467113 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -5.80483746488798\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.98276931479723 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -2.58487674308692\n",
       "                                                                 Pr(>|t|)            \n",
       "imputed_new_buses                                                6.23290612101973e-05\n",
       "imputed_new_buses:single_stop_10_ride                            0.628105182568772   \n",
       "Is405North_10_ride:I405HOV                                       1.14524242848869e-07\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     6.44565818674655e-09\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   6.81238545722762e-05\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.00974158503900379 \n",
       "                                                                 r2               \n",
       "imputed_new_buses                                                0.319910393524676\n",
       "imputed_new_buses:single_stop_10_ride                            0.319910393524676\n",
       "Is405North_10_ride:I405HOV                                       0.319910393524676\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.319910393524676\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.319910393524676\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.319910393524676\n",
       "                                                                 N     \n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   689102\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 689102\n",
       "                                                                 granularity       \n",
       "imputed_new_buses                                                rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M5 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 4 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                                </td><td>0.00931357756704925                              </td><td>0.00445537978838421                              </td><td>2.09041159439001                                 </td><td>0.0365836787311989                               </td><td>0.377208112151117                                </td><td>88994                                            </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                </td><td>0.00211526784534133                              </td><td>0.00186114683008929                              </td><td>1.13654001454568                                 </td><td>0.255731024058471                                </td><td>0.319809286311396                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                                                </td><td>0.00521643991356266                              </td><td>0.00217185454431983                              </td><td>2.40183668248203                                 </td><td>0.0163132527431281                               </td><td>0.319809286311396                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                </td><td>0.0628511723878487                               </td><td>0.0657302253213042                               </td><td>0.956198949275132                                </td><td>0.338972066240506                                </td><td>0.319889816181573                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                                                </td><td>0.0557814133181326                               </td><td>0.00810988938632222                              </td><td>6.87819656482751                                 </td><td>6.06663120489689e-12                             </td><td>0.319889816181573                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                                                </td><td>-0.0543654048593643                              </td><td>0.0654995990023083                               </td><td>-0.830011262472742                               </td><td>0.406532703630587                                </td><td>0.319889816181573                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                                                </td><td>0.106422839326307                                </td><td>0.0875479801184227                               </td><td>1.21559445668938                                 </td><td>0.224139863421881                                </td><td>0.319889816181573                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                                                </td><td>-0.136158432437297                               </td><td>0.0875093383844803                               </td><td>-1.55593031499189                                </td><td>0.119725123167939                                </td><td>0.319889816181573                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                </td><td>0.00853347664041471                              </td><td>0.00203388572695324                              </td><td>4.19565196182278                                 </td><td>2.72121795528025e-05                             </td><td>0.319903797330774                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                                                </td><td>-0.00062454108055395                             </td><td>0.00271983779498736                              </td><td>-0.22962438484566                                </td><td>0.81838372493912                                 </td><td>0.319903797330774                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0400377259018087                               </td><td>0.00644763793034833                              </td><td>6.20967342371312                                 </td><td>5.31249524023138e-10                             </td><td>0.319903797330774                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.0298398708671568                              </td><td>0.00359141973270209                              </td><td>-8.30865593220597                                </td><td>9.6964482878064e-17                              </td><td>0.319903797330774                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0155669799634182                               </td><td>0.00404142125154769                              </td><td>3.85185779815868                                 </td><td>0.000117235692783138                             </td><td>0.319903797330774                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                </td><td>0.00816346309887731                              </td><td>0.00203890845192655                              </td><td>4.00383994247692                                 </td><td>6.23290612101973e-05                             </td><td>0.319910393524676                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                                                </td><td>0.00136943719761286                              </td><td>0.00282710402757675                              </td><td>0.484395757727626                                </td><td>0.628105182568772                                </td><td>0.319910393524676                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.035454732615988                                </td><td>0.00668694477164967                              </td><td>5.30208246467113                                 </td><td>1.14524242848869e-07                             </td><td>0.319910393524676                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0242895117885626                              </td><td>0.00418435691532861                              </td><td>-5.80483746488798                                </td><td>6.44565818674655e-09                             </td><td>0.319910393524676                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0376740364022946                               </td><td>0.00945925646818754                              </td><td>3.98276931479723                                 </td><td>6.81238545722762e-05                             </td><td>0.319910393524676                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0267864394059024                              </td><td>0.0103627530703509                               </td><td>-2.58487674308692                                </td><td>0.00974158503900379                              </td><td>0.319910393524676                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                                     & 0.00931357756704925                                   & 0.00445537978838421                                   & 2.09041159439001                                      & 0.0365836787311989                                    & 0.377208112151117                                     & 88994                                                 & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\timputed\\_new\\_buses & 2                                                 & 0.00211526784534133                               & 0.00186114683008929                               & 1.13654001454568                                  & 0.255731024058471                                 & 0.319809286311396                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                                                 & 0.00521643991356266                               & 0.00217185454431983                               & 2.40183668248203                                  & 0.0163132527431281                                & 0.319809286311396                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 3                                                 & 0.0628511723878487                                & 0.0657302253213042                                & 0.956198949275132                                 & 0.338972066240506                                 & 0.319889816181573                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                                                 & 0.0557814133181326                                & 0.00810988938632222                               & 6.87819656482751                                  & 6.06663120489689e-12                              & 0.319889816181573                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                                                 & -0.0543654048593643                               & 0.0654995990023083                                & -0.830011262472742                                & 0.406532703630587                                 & 0.319889816181573                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                                                 & 0.106422839326307                                 & 0.0875479801184227                                & 1.21559445668938                                  & 0.224139863421881                                 & 0.319889816181573                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                                                 & -0.136158432437297                                & 0.0875093383844803                                & -1.55593031499189                                 & 0.119725123167939                                 & 0.319889816181573                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 4                                                 & 0.00853347664041471                               & 0.00203388572695324                               & 4.19565196182278                                  & 2.72121795528025e-05                              & 0.319903797330774                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                                                 & -0.00062454108055395                              & 0.00271983779498736                               & -0.22962438484566                                 & 0.81838372493912                                  & 0.319903797330774                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                                                 & 0.0400377259018087                                & 0.00644763793034833                               & 6.20967342371312                                  & 5.31249524023138e-10                              & 0.319903797330774                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.0298398708671568                               & 0.00359141973270209                               & -8.30865593220597                                 & 9.6964482878064e-17                               & 0.319903797330774                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                                                 & 0.0155669799634182                                & 0.00404142125154769                               & 3.85185779815868                                  & 0.000117235692783138                              & 0.319903797330774                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 5                                                 & 0.00816346309887731                               & 0.00203890845192655                               & 4.00383994247692                                  & 6.23290612101973e-05                              & 0.319910393524676                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                                                 & 0.00136943719761286                               & 0.00282710402757675                               & 0.484395757727626                                 & 0.628105182568772                                 & 0.319910393524676                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                                                 & 0.035454732615988                                 & 0.00668694477164967                               & 5.30208246467113                                  & 1.14524242848869e-07                              & 0.319910393524676                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0242895117885626                               & 0.00418435691532861                               & -5.80483746488798                                 & 6.44565818674655e-09                              & 0.319910393524676                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.0376740364022946                                & 0.00945925646818754                               & 3.98276931479723                                  & 6.81238545722762e-05                              & 0.319910393524676                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0267864394059024                               & 0.0103627530703509                                & -2.58487674308692                                 & 0.00974158503900379                               & 0.319910393524676                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                                 | 0.00931357756704925                               | 0.00445537978838421                               | 2.09041159439001                                  | 0.0365836787311989                                | 0.377208112151117                                 | 88994                                             | rider/date/commute [Single Stop Preferred Riders] |\n",
       "| imputed_new_buses | 2                                                 | 0.00211526784534133                               | 0.00186114683008929                               | 1.13654001454568                                  | 0.255731024058471                                 | 0.319809286311396                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                                                 | 0.00521643991356266                               | 0.00217185454431983                               | 2.40183668248203                                  | 0.0163132527431281                                | 0.319809286311396                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses | 3                                                 | 0.0628511723878487                                | 0.0657302253213042                                | 0.956198949275132                                 | 0.338972066240506                                 | 0.319889816181573                                 | 689102                                            | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 3                                                 | 0.0557814133181326                                | 0.00810988938632222                               | 6.87819656482751                                  | 6.06663120489689e-12                              | 0.319889816181573                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:I405HOV | 3                                                 | -0.0543654048593643                               | 0.0654995990023083                                | -0.830011262472742                                | 0.406532703630587                                 | 0.319889816181573                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                                                 | 0.106422839326307                                 | 0.0875479801184227                                | 1.21559445668938                                  | 0.224139863421881                                 | 0.319889816181573                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                                                 | -0.136158432437297                                | 0.0875093383844803                                | -1.55593031499189                                 | 0.119725123167939                                 | 0.319889816181573                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses | 4                                                 | 0.00853347664041471                               | 0.00203388572695324                               | 4.19565196182278                                  | 2.72121795528025e-05                              | 0.319903797330774                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                                                 | -0.00062454108055395                              | 0.00271983779498736                               | -0.22962438484566                                 | 0.81838372493912                                  | 0.319903797330774                                 | 689102                                            | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 4                                                 | 0.0400377259018087                                | 0.00644763793034833                               | 6.20967342371312                                  | 5.31249524023138e-10                              | 0.319903797330774                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                                                 | -0.0298398708671568                               | 0.00359141973270209                               | -8.30865593220597                                 | 9.6964482878064e-17                               | 0.319903797330774                                 | 689102                                            | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                                                 | 0.0155669799634182                                | 0.00404142125154769                               | 3.85185779815868                                  | 0.000117235692783138                              | 0.319903797330774                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses | 5                                                 | 0.00816346309887731                               | 0.00203890845192655                               | 4.00383994247692                                  | 6.23290612101973e-05                              | 0.319910393524676                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                                                 | 0.00136943719761286                               | 0.00282710402757675                               | 0.484395757727626                                 | 0.628105182568772                                 | 0.319910393524676                                 | 689102                                            | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 5                                                 | 0.035454732615988                                 | 0.00668694477164967                               | 5.30208246467113                                  | 1.14524242848869e-07                              | 0.319910393524676                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                                                 | -0.0242895117885626                               | 0.00418435691532861                               | -5.80483746488798                                 | 6.44565818674655e-09                              | 0.319910393524676                                 | 689102                                            | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | 0.0376740364022946                                | 0.00945925646818754                               | 3.98276931479723                                  | 6.81238545722762e-05                              | 0.319910393524676                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | -0.0267864394059024                               | 0.0103627530703509                                | -2.58487674308692                                 | 0.00974158503900379                               | 0.319910393524676                                 | 689102                                            | rider/date/commute                                |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "                                                                 1    \n",
       "imputed_new_buses                                                2    \n",
       "imputed_new_buses:single_stop_10_ride                            2    \n",
       "imputed_new_buses                                                3    \n",
       "Is405North_10_ride:I405HOV                                       3    \n",
       "imputed_new_buses:I405HOV                                        3    \n",
       "imputed_new_buses:Is405North_10_ride                             3    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     3    \n",
       "imputed_new_buses                                                4    \n",
       "imputed_new_buses:single_stop_10_ride                            4    \n",
       "Is405North_10_ride:I405HOV                                       4    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     4    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4    \n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate            \n",
       "                                                                 0.00931357756704925 \n",
       "imputed_new_buses                                                0.00211526784534133 \n",
       "imputed_new_buses:single_stop_10_ride                            0.00521643991356266 \n",
       "imputed_new_buses                                                0.0628511723878487  \n",
       "Is405North_10_ride:I405HOV                                       0.0557814133181326  \n",
       "imputed_new_buses:I405HOV                                        -0.0543654048593643 \n",
       "imputed_new_buses:Is405North_10_ride                             0.106422839326307   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.136158432437297  \n",
       "imputed_new_buses                                                0.00853347664041471 \n",
       "imputed_new_buses:single_stop_10_ride                            -0.00062454108055395\n",
       "Is405North_10_ride:I405HOV                                       0.0400377259018087  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0298398708671568 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0155669799634182  \n",
       "imputed_new_buses                                                0.00816346309887731 \n",
       "imputed_new_buses:single_stop_10_ride                            0.00136943719761286 \n",
       "Is405North_10_ride:I405HOV                                       0.035454732615988   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0242895117885626 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0376740364022946  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0267864394059024 \n",
       "                                                                 Std. Error         \n",
       "                                                                 0.00445537978838421\n",
       "imputed_new_buses                                                0.00186114683008929\n",
       "imputed_new_buses:single_stop_10_ride                            0.00217185454431983\n",
       "imputed_new_buses                                                0.0657302253213042 \n",
       "Is405North_10_ride:I405HOV                                       0.00810988938632222\n",
       "imputed_new_buses:I405HOV                                        0.0654995990023083 \n",
       "imputed_new_buses:Is405North_10_ride                             0.0875479801184227 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0875093383844803 \n",
       "imputed_new_buses                                                0.00203388572695324\n",
       "imputed_new_buses:single_stop_10_ride                            0.00271983779498736\n",
       "Is405North_10_ride:I405HOV                                       0.00644763793034833\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.00359141973270209\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00404142125154769\n",
       "imputed_new_buses                                                0.00203890845192655\n",
       "imputed_new_buses:single_stop_10_ride                            0.00282710402757675\n",
       "Is405North_10_ride:I405HOV                                       0.00668694477164967\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.00418435691532861\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00945925646818754\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.0103627530703509 \n",
       "                                                                 t value           \n",
       "                                                                 2.09041159439001  \n",
       "imputed_new_buses                                                1.13654001454568  \n",
       "imputed_new_buses:single_stop_10_ride                            2.40183668248203  \n",
       "imputed_new_buses                                                0.956198949275132 \n",
       "Is405North_10_ride:I405HOV                                       6.87819656482751  \n",
       "imputed_new_buses:I405HOV                                        -0.830011262472742\n",
       "imputed_new_buses:Is405North_10_ride                             1.21559445668938  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -1.55593031499189 \n",
       "imputed_new_buses                                                4.19565196182278  \n",
       "imputed_new_buses:single_stop_10_ride                            -0.22962438484566 \n",
       "Is405North_10_ride:I405HOV                                       6.20967342371312  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -8.30865593220597 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.85185779815868  \n",
       "imputed_new_buses                                                4.00383994247692  \n",
       "imputed_new_buses:single_stop_10_ride                            0.484395757727626 \n",
       "Is405North_10_ride:I405HOV                                       5.30208246467113  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -5.80483746488798 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.98276931479723  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -2.58487674308692 \n",
       "                                                                 Pr(>|t|)            \n",
       "                                                                 0.0365836787311989  \n",
       "imputed_new_buses                                                0.255731024058471   \n",
       "imputed_new_buses:single_stop_10_ride                            0.0163132527431281  \n",
       "imputed_new_buses                                                0.338972066240506   \n",
       "Is405North_10_ride:I405HOV                                       6.06663120489689e-12\n",
       "imputed_new_buses:I405HOV                                        0.406532703630587   \n",
       "imputed_new_buses:Is405North_10_ride                             0.224139863421881   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.119725123167939   \n",
       "imputed_new_buses                                                2.72121795528025e-05\n",
       "imputed_new_buses:single_stop_10_ride                            0.81838372493912    \n",
       "Is405North_10_ride:I405HOV                                       5.31249524023138e-10\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     9.6964482878064e-17 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.000117235692783138\n",
       "imputed_new_buses                                                6.23290612101973e-05\n",
       "imputed_new_buses:single_stop_10_ride                            0.628105182568772   \n",
       "Is405North_10_ride:I405HOV                                       1.14524242848869e-07\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     6.44565818674655e-09\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   6.81238545722762e-05\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.00974158503900379 \n",
       "                                                                 r2               \n",
       "                                                                 0.377208112151117\n",
       "imputed_new_buses                                                0.319809286311396\n",
       "imputed_new_buses:single_stop_10_ride                            0.319809286311396\n",
       "imputed_new_buses                                                0.319889816181573\n",
       "Is405North_10_ride:I405HOV                                       0.319889816181573\n",
       "imputed_new_buses:I405HOV                                        0.319889816181573\n",
       "imputed_new_buses:Is405North_10_ride                             0.319889816181573\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.319889816181573\n",
       "imputed_new_buses                                                0.319903797330774\n",
       "imputed_new_buses:single_stop_10_ride                            0.319903797330774\n",
       "Is405North_10_ride:I405HOV                                       0.319903797330774\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.319903797330774\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.319903797330774\n",
       "imputed_new_buses                                                0.319910393524676\n",
       "imputed_new_buses:single_stop_10_ride                            0.319910393524676\n",
       "Is405North_10_ride:I405HOV                                       0.319910393524676\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.319910393524676\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.319910393524676\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.319910393524676\n",
       "                                                                 N     \n",
       "                                                                 88994 \n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "imputed_new_buses                                                689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:I405HOV                                        689102\n",
       "imputed_new_buses:Is405North_10_ride                             689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   689102\n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   689102\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 689102\n",
       "                                                                 granularity                                      \n",
       "                                                                 rider/date/commute [Single Stop Preferred Riders]\n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:I405HOV                                        rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride                             rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute                               "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_4 <- rbind(T4_M1,T4_M2,T4_M3,T4_M4,T4_M5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>used</th><th scope=col>(Mb)</th><th scope=col>gc trigger</th><th scope=col>(Mb)</th><th scope=col>max used</th><th scope=col>(Mb)</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>Ncells</th><td>  668126  </td><td> 35.7     </td><td>  2310793 </td><td> 123.5    </td><td>   8814980</td><td>  470.8   </td></tr>\n",
       "\t<tr><th scope=row>Vcells</th><td>65566544  </td><td>500.3     </td><td>860528926 </td><td>6565.4    </td><td>2913357389</td><td>22227.2   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllll}\n",
       "  & used & (Mb) & gc trigger & (Mb) & max used & (Mb)\\\\\n",
       "\\hline\n",
       "\tNcells &   668126   &  35.7      &   2310793  &  123.5     &    8814980 &   470.8   \\\\\n",
       "\tVcells & 65566544   & 500.3      & 860528926  & 6565.4     & 2913357389 & 22227.2   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | used | (Mb) | gc trigger | (Mb) | max used | (Mb) |\n",
       "|---|---|---|---|---|---|---|\n",
       "| Ncells |   668126   |  35.7      |   2310793  |  123.5     |    8814980 |   470.8    |\n",
       "| Vcells | 65566544   | 500.3      | 860528926  | 6565.4     | 2913357389 | 22227.2    |\n",
       "\n"
      ],
      "text/plain": [
       "       used     (Mb)  gc trigger (Mb)   max used   (Mb)   \n",
       "Ncells   668126  35.7   2310793   123.5    8814980   470.8\n",
       "Vcells 65566544 500.3 860528926  6565.4 2913357389 22227.2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "gc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
